<?php

namespace app\api\controller\cms;
use app\api\service\cms\MenuService;
use think\Request;

class Menu
{
    protected $Service;
    public function __construct()
    {
        $this->Service = MenuService::getInstance();
    }

    /**
     * @auth('创建管理后台菜单','管理员','hidden')
     * @param Request $request
     * @return \think\response\Json
     */
    public function createMenu(Request $request){
        $params = $request->post();
        $this->Service->createMenu($params);
        return writeJson(201, '', '菜单创建成功');
    }


    /**
     * @auth('更新管理后台菜单','管理员','hidden')
     * @param Request $request
     * @return \think\response\Json
     */
    public function updateMenu(Request $request){
        $params = $request->param();
        $this->Service->updateMenu($params);
        return writeJson(201, '', '菜单修改成功');
    }

    /**
     * @auth('删除管理后台菜单','管理员','hidden')
     * @param $id
     * @return \think\response\Json
     */
    public function deleteMenu($id){
        $this->Service->deleteMenu($id);
        return writeJson(201, '', '菜单删除成功');
    }


    /**
     * @auth('查询管理后台菜单','管理员','hidden')
     * @param Request $request
     * @param('page','页数','require')
     * @return \think\response\Json
     */
    public function getMenu(Request $request){
        $params = $request->get();
        $result = $this->Service->getMenu($params);
        return writeJson(201, $result, '数据列表');
    }

//    /**
//     * @auth('查询管理后台菜单树状图','管理员','hidden')
//     * @return \think\response\Json
//     */
    public function getMenuStructure(){
        $result = $this->Service->getMenuStructure();
        return writeJson(201, $result, '数据列表');
    }

    /**
     * @auth('查询管理后台菜单指定','管理员','hidden')
     * @param $id
     * @return \think\response\Json
     */
    public function getMenuOne($id){
        $result = $this->Service->getMenuOne($id);
        return writeJson(201, $result, '数据列表');
    }

    /**
     * @auth('查询管理后台菜单指定','管理员','hidden')
     * @param $groupId
     * @return \think\response\Json
     */
    public function getAppointMenu($groupId){
        $result = $this->Service->getAppointMenu($groupId);
        return writeJson(201, $result, '数据列表');
    }

    /**
     * @auth('用户菜单配置变更','管理员','hidden')
     * @param Request $request
     * @return \think\response\Json
     */
    public function setAppointMenu(Request $request){
        $params = $request->post();
        $result = $this->Service->setAppointMenu($params);
        return writeJson(201, $result, '完成');
    }


    public function getAppointUserRoute(){
        $result = $this->Service->getAppointUserRoute();
        return writeJson(201, $result, '数据列表');
    }

}
